
package org.jeecg.modules.friends.base;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;


@Setter
@Getter
@ApiModel(value = "通用返回")
public class HttpReturn<V> implements Serializable {

    @ApiModelProperty(value = "接口返回状态, 正常为0 ，也就是返回的数是预期所要的数据结果")
    private Integer status;

    @ApiModelProperty(value = "描述字符串")
    private String msg;

    /**
     * 接口返回数据
     */
    @ApiModelProperty(value = "接口返回数据")
    private V result;

    public static <V> HttpReturn<V> successResult(V v) {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
        r.setStatus(ReturnStatusEnum.SUCCESS.getCode());
        r.setResult(v);
        return r;
    }

    public static <V> HttpReturn<V> successResult() {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
        r.setStatus(ReturnStatusEnum.SUCCESS.getCode());
        return r;
    }

    public static <E> HttpReturn<PageRsp<E>> successPageResult(PageRsp<E> page) {
        HttpReturn<PageRsp<E>> r = new HttpReturn<>();
        r.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
        r.setStatus(ReturnStatusEnum.SUCCESS.getCode());
        r.setResult(page);
        return r;
    }

    public static <E> HttpReturn<PageRsp<E>> successPageResult() {
        HttpReturn<PageRsp<E>> r = new HttpReturn<>();
        r.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
        r.setStatus(ReturnStatusEnum.SUCCESS.getCode());
        r.setResult(null);
        return r;
    }

    /**
     * 参数错误
     *
     * @param v 消息
     */
    public static <V> HttpReturn<V> failParamResult(V v) {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg((String) v);
        r.setStatus(ReturnStatusEnum.PARAM_ERROR.getCode());
        return r;
    }

    /**
     * 获取为非预期数据
     *
     * @param msg 消息
     */
    public static <V> HttpReturn<V> failResult(String msg) {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg(msg);
        r.setStatus(ReturnStatusEnum.NOT_EXPECT_DATA.getCode());
        return r;
    }

    public static <V> HttpReturn<V> failResult(String msg, V v) {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg(msg);
        r.setResult(v);
        r.setStatus(ReturnStatusEnum.NOT_EXPECT_DATA.getCode());
        return r;
    }

    public static <V> HttpReturn<V> failResult(String msg, Integer status) {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg(msg);
        r.setStatus(status);
        return r;
    }

    public static <V> HttpReturn<V> failResult(String msg, V v, Integer status) {
        HttpReturn<V> r = new HttpReturn<>();
        r.setMsg(msg);
        r.setResult(v);
        r.setStatus(status);
        return r;
    }
}
